import java.util.StringJoiner;

public class Test {
    public static void main(String[] args) {
        // StringJoiner：拼接字符串数组
        String[] words = { "Hello", "world", "this", "is", "Java" };
        StringJoiner sj = new StringJoiner(",", "***", "###"); // 以空格作为分隔符, 前缀为***，后缀为###
        for (String word : words) {
            sj.add(word);
        }
        System.out.println(sj.toString());
        // String还提供了一个静态方法join(): 不能指定“开头”和“结尾
        String result = String.join(" - ", words);
        System.out.println(result);
    }
}
